package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author liuchun
 * @since 2024-10-23
 */
@Api("优惠券管理相关接口")
@RestController
@RequestMapping("/coupons")
public class CouponController {


    @Autowired
    private ICouponService couponService;

    ////新增优惠券
    @ApiOperation("新增优惠券接口")
    @PostMapping
    public void addCoupons(@RequestBody @Validated CouponFormDTO couponFormDTO) {
        couponService.addCoupons(couponFormDTO);
    }

    //分页查询优惠券
    @ApiOperation("分页查询优惠券")
    @GetMapping("/page")
    public PageDTO<CouponPageVO> selectCouponsPage(CouponQuery query) {
        return couponService.selectCouponsPage(query);
    }
    //发放优惠券
    @ApiOperation("发放优惠券")
    @PutMapping("/{id}/issue")
    public void issueCoupons(@PathVariable Long id, @RequestBody @Validated CouponIssueFormDTO dto) {
        couponService.issueCoupons(id, dto);
    }
    //查询发放中的优惠券
    @ApiOperation("查询发放中的优惠券")
    @GetMapping("/list")
    public List<CouponVO> listAllIssuingCoupons() {
        return couponService.listAllIssuingCoupons();
    }
}

